package com.bear.hospital.controller;

import com.bear.hospital.aspect.LogRequestParamResponse;
import com.bear.hospital.entity.LoginInfo;
import com.bear.hospital.service.login.LoginService;
import com.bear.hospital.utils.ResponseData;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @Author： zmwx
 * @Date： 2025/1/23 15:42
 * @Describe：
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Resource
    private LoginService loginService;

    @LogRequestParamResponse
    @PostMapping("/loginSystem")
    public ResponseData login(@RequestBody LoginInfo loginInfo) {
        if (!ObjectUtils.isNotEmpty(loginInfo)) {
            return new ResponseData(500, "参数为空", new HashMap<>());
        }
        if (ObjectUtils.isNotEmpty(loginInfo.getLoginUrl()) && ObjectUtils.isNotEmpty(loginInfo.getPassword()) || StringUtils.isBlank(loginInfo.getUserName())) {
            return new ResponseData(500, "用户名或密码为空", new HashMap<>());
        }

        return loginService.AutoIdentityLogin(loginInfo);
    }

    @PostMapping("/uploadSetProfilePhoto")
    public ResponseData uploadSetProfilePhoto(@RequestParam("file") MultipartFile file) {
        return loginService.uploadSetProfilePhoto(file);

    }
}
